﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tradex.Market {
    
    /// <summary>
    /// This class represents an aggregation of market updates, created from an
    /// aggregatror and for further use in either trading systems of visualization.
    /// 
    /// This is commonly referred to as a "bar", but must not necessarily represent
    /// the intention of showing a bar, for example in a point and figure chart.
    /// </summary>
    public class ActivityAggregate {

        /// <summary>
        /// The constructor for the aggregate, taking a market update. This creates
        /// an initial Aggregate easily, by just feeding it a market update.
        /// </summary>
        /// <param name="update"></param>
        public ActivityAggregate(
            Activity update
        ) {
            if (update == null) {
                throw new ArgumentException("value can not be null", "update");
            }
            Open = update.Price;
            High = update.Price;
            Low = update.Price;
            Close = update.Price;
            Updates = 1;
            Volume = update.Volume;
            StartTime = update.Timestamp;
            EndTime = update.Timestamp;
        }

        /// <summary>
        ///  The constructor of the aggregate taking all individual elements.
        /// </summary>
        /// <param name="open"></param>
        /// <param name="high"></param>
        /// <param name="low"></param>
        /// <param name="close"></param>
        /// <param name="updates"></param>
        /// <param name="volume"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        public ActivityAggregate(
            double open,
            double high,
            double low,
            double close,
            int updates,
            ulong volume,
            DateTime startTime,
            DateTime endTime
        ) {
            Open = open;
            High = high;
            Low = low;
            Close = close;
            Updates = updates;
            Volume = volume;
            StartTime = startTime;
            EndTime = endTime;

        }

        /// <summary>
        /// Empty public constructor.
        /// // Needed?
        /// </summary>
        public ActivityAggregate () {
        }

        /// <summary>
        /// This is the open trade price.
        /// </summary>
        public double Open { get; private set; }

        /// <summary>
        /// Gets the highest traded value in the aggregate.
        /// </summary>
        public double High { get; private set; }

        /// <summary>
        /// Gets the lowest traded value in the aggregate.
        /// </summary>
        public double Low { get; private set; }

        /// <summary>
        /// Gets the last traded value.
        /// </summary>
        public double Close { get; private set; }

        /// <summary>
        /// Gets the number of market updates included.
        /// </summary>
        public int Updates { get; private set; }

        /// <summary>
        /// Gets the total volume of all trades.
        /// </summary>
        public ulong Volume { get; private set; }

        /// <summary>
        /// Gets the timestamp of the start.
        /// </summary>
        public DateTime StartTime { get; private set; }

        /// <summary>
        /// Gets the timestamp of the end.
        /// </summary>
        public DateTime EndTime { get; private set; }

    }

}
